package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.DigitalCollectionProductInfoAuctionUserBidding;
import com.sc.nft.entity.vo.AuctionConsumeAdminPageVO;
import com.sc.nft.entity.vo.AuctionConsumeUserDetailAdminPageVO;
import com.sc.nft.entity.vo.DigitalCollectionProductInfoAuctionUserBiddingResultsVO;
import com.sc.nft.entity.vo.UserAuctionRecordPageVO;
import com.sc.nft.mapper.DigitalCollectionProductInfoAuctionUserBiddingMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.apache.lucene.search.similarities.Lambda;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author：LiGen
 * @Package：com.sc.nft.dao
 * @Project：sc_metago
 * @name：DigitalCollectionProductInfoAuctionDao
 * @Date：2024/9/5 14:57
 * @Filename：DigitalCollectionProductInfoAuctionDao
 */
@Slf4j
@Repository
public class DigitalCollectionProductInfoAuctionUserBiddingDao extends ServiceImpl<DigitalCollectionProductInfoAuctionUserBiddingMapper, DigitalCollectionProductInfoAuctionUserBidding> {
    /**
     * 用户拍卖记录
     *
     * @param userId
     * @param mp
     * @return
     */
    public IPage<UserAuctionRecordPageVO> auctionRecords(Long userId, Page mp) {
        return baseMapper.auctionRecords(mp,userId);
    }

    public List<DigitalCollectionProductInfoAuctionUserBidding> listByProductIdAndUserId(Long userId, Long productId) {
        LambdaQueryWrapper<DigitalCollectionProductInfoAuctionUserBidding> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DigitalCollectionProductInfoAuctionUserBidding::getProductId, productId);
        wrapper.eq(DigitalCollectionProductInfoAuctionUserBidding::getUserId, userId);
        wrapper.orderByDesc(DigitalCollectionProductInfoAuctionUserBidding::getCreateTime);
        return list(wrapper);
    }

    public Integer countByProductIdAndUserId(Long userId, Long productId) {
        LambdaQueryWrapper<DigitalCollectionProductInfoAuctionUserBidding> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DigitalCollectionProductInfoAuctionUserBidding::getProductId, productId);
        wrapper.eq(DigitalCollectionProductInfoAuctionUserBidding::getUserId, userId);
        return count(wrapper);
    }

    /**
     * 获取拍卖投注的数量结果
     *
     * @param productId      拍卖商品ID
     * @return
     */
    public List<DigitalCollectionProductInfoAuctionUserBiddingResultsVO> getResultsVOList(Long productId) {
        return baseMapper.getResultsVOList(productId);
    }


    /**
     * 消耗藏品总数列表
     * @param productId
     * @param page
     * @return
     */
    public Page<AuctionConsumeAdminPageVO> getAuctionConsumeAdminPage(Long productId, Page page) {
        return baseMapper.auctionConsumeAdminPage(productId,page);
    }


    /**
     * 用户消耗总数详情列表
     * @param productId
     * @param page
     * @return
     */
    public Page<AuctionConsumeUserDetailAdminPageVO> getAuctionConsumeUserDetailAdminPage(Long productId,Long userId,Page page) {
        return baseMapper.auctionConsumeUserDetailAdminPage(productId,userId,page);
    }

    public Integer countByProductId(Long productId) {
        LambdaQueryWrapper<DigitalCollectionProductInfoAuctionUserBidding> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DigitalCollectionProductInfoAuctionUserBidding::getProductId, productId);
        return count(wrapper);
    }
}
